<?php

//此文件仅仅为测试 练习而已
function makeSign($arr)
{
	//排序
	ksort($arr);
	//格式化参数格式化成url参数
	$buff = "";
	foreach ($arr as $k => $v)
	{
		if($k != "sign" && $v != "" && !is_array($v)){
			$buff .= $k . "=" . $v . "&";
		}
	}
	$buff = trim($buff, "&");
	$string = $buff."&key=NJSglVKnYArumYiayHUZAfXPikbGRJX3";//累加api支付秘钥
	$string = md5($string);
	$result = strtoupper($string);
	return $result;
}

function checkSign($arr)
{
	if(makeSign($arr) === $arr['sign'])
	{
		return true;
	}
	else 
	{
		return false;
	}
}

$str='a:16:{s:5:"appid";s:18:"wx7ea367b003ea9667";s:9:"bank_type";s:9:"ABC_DEBIT";s:8:"cash_fee";s:1:"1";s:8:"fee_type";s:3:"CNY";s:12:"is_subscribe";s:1:"N";s:6:"mch_id";s:10:"1264106101";s:9:"nonce_str";s:32:"2a7872fbddf185df0b728ed23af8fd6c";s:6:"openid";s:28:"o52kuwfix3mjYQslgSWj_rwf5c5g";s:12:"out_trade_no";s:20:"20150817211512421837";s:11:"result_code";s:7:"SUCCESS";s:11:"return_code";s:7:"SUCCESS";s:4:"sign";s:32:"48521620DE2329DCAFEFFF1910D2C9D6";s:8:"time_end";s:14:"20150817211522";s:9:"total_fee";s:1:"1";s:10:"trade_type";s:3:"APP";s:14:"transaction_id";s:28:"1006660377201508170643770042";}';
$arr=unserialize($str);
$sign=$arr['sign'];
if(checkSign($arr))
{
	echo 'hello';
}




//签名步骤一：按字典序排序参数
//		ksort($this->values);
//		$string = $this->ToUrlParams();
//		//签名步骤二：在string后加入KEY
//		$string = $string . "&key=".WxPayConfig::KEY;
//		//签名步骤三：MD5加密
//		$string = md5($string);
//		//签名步骤四：所有字符转为大写
//		$result = strtoupper($string);




//$data['appid']='wx7ea367b003ea9667';
//$data['partnerid']='1264106101';
//$data['prepayid']='';//自己第一次得到的
//$data['package']="Sign=WXPay";
//$data['noncestr']=$arr['nonce_str'];//随机字符串
//$data['timestamp']=$arr['time_end'];//时间戳
//$data['sign']='';//签名




//class WxCheck
//{
//	static $val=array("appid"=>'wx7ea367b003ea9667','mchid'=>'1225312702');
///**
//	 * 格式化参数格式化成url参数
//	 */
//	static function ToUrlParams()
//	{
//		$buff = "";
//		foreach (self::val as $k => $v)
//		{
//			if($k != "sign" && $v != "" && !is_array($v)){
//				$buff .= $k . "=" . $v . "&";
//			}
//		}
//		
//		$buff = trim($buff, "&");
//		return $buff;
//	}
//	static function makeSign()
//	{
//		ksort(self::val);
//		$string = self::ToUrlParams();
//		//签名步骤二：在string后加入KEY
//		$string = $string . "&key=NJSglVKnYArumYiayHUZAfXPikbGRJX3";
//		//签名步骤三：MD5加密
//		$string = md5($string);
//		//签名步骤四：所有字符转为大写
//		$result = strtoupper($string);
//		return $result;
//	}
//}
//echo WxCheck::makeSign();






?>